package com.xinqi.modules.stats.score.controller.web;

import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.stats.score.dto.req.*;
import com.xinqi.modules.stats.score.dto.rsp.*;
import com.xinqi.modules.stats.score.service.CourseTotalScoreContentService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreStudentService;
import com.xinqi.modules.stats.score.service.CourseTotalScoreTypeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 成绩管理WEB控制层
 *
 * @author: dzy
 * @date: 2023/03/26
 */
@Tag(name = "成绩管理总成绩WEB端", description = "成绩管理总成绩WEB端")
@Validated
@RestController
@RequestMapping("/web/total-score")
@RequiredArgsConstructor
public class CourseTotalScoreWebController {

    private final CourseTotalScoreService courseTotalScoreService;

    private final CourseTotalScoreContentService courseTotalScoreContentService;

    private final CourseTotalScoreTypeService courseTotalScoreTypeService;

    private final CourseTotalScoreStudentService courseTotalScoreStudentService;


    //======================功能变更V2======================================
    /**
     * 分类成绩查询-老师端-分页-V2
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/teacher/type/score/pagev2")
    public R<PageInfo<TotalScoreStudentListDTO>> teacherTypeScorePageV2(@Validated CourseTotalScoreTypeQueryDTO dto) {
        return R.data(courseTotalScoreTypeService.teacherTypeScorePageV2(dto));
    }

    /**
     * 分类成绩详情查询-老师端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/teacher/type/detail")
    public R<TeacherStudentTotalScoreResultDTO> teacherTypeDetail(CourseTotalScoreTypeDetailQueryDTO dto) {
        return R.data(courseTotalScoreTypeService.teacherTypeDetail(dto));
    }

    /**
     * 分类成绩查询-学生端-分页
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/type/score/page")
    public R<PageInfo<TotalScoreStudentListDTO>> typeScorePage(CourseTotalScoreTypeQueryDTO dto) {
        dto.setStudentId(LoginHelper.getUserId());
        return R.data(courseTotalScoreTypeService.typeScorePage(dto));
    }

    //==========================以下为弃用的接口==========================================
    /**
     * 总分、对学生显示成绩、是否使用等级分制设置
     * @param dto 初始化参数
     * @return
     */
    @PostMapping("/set")
    public R<String> set(@RequestBody CourseTotalScoreCreateDTO dto) {
        if (courseTotalScoreService.setCourseTotalScore(dto)) {
            return R.ok("设置成功");
        } else {
            return R.fail("设置失败");
        }
    }


    /**
     * 获取总成绩设置信息
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/data")
    public R<CourseTotalScoreResultDTO> list(CourseTotalScoreClassDTO dto) {
        return R.ok(courseTotalScoreService.findCourseTotalScore(dto));
    }

    /**
     * 成绩管理完成设置
     * @param dto 初始化参数
     * @return
     */
    @PostMapping("/complete")
    public R<String> complete(@RequestBody CourseTotalScoreContentCompleteDTO dto) {
        if (courseTotalScoreContentService.complete(dto)) {
            return R.ok("设置成功");
        } else {
            return R.fail("设置失败");
        }
    }

    /**
     * 总成绩查询-老师端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/main")
    public R<TotalScoreStudentScoreTeacherDTO> scoreMain(CourseTotalScoreClassDTO dto) {
        return R.data(courseTotalScoreService.main(dto));
    }

    /**
     * 获取总成绩成绩分布图
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/column/data")
    public R<CourseTotalScoreColumnResultDTO> data(CourseTotalScoreClassDTO dto) {
        return R.data(courseTotalScoreStudentService.studentTotalScoreColumnList(dto));
    }

    /**
     * 获取总成绩成绩学生列转行列表PC端 -- 老师端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/student")
    public R<CourseContentTotalScorePCResultDTO> pcListStudent(CourseTotalScoreClassDTO dto) {
        return R.data(courseTotalScoreService.studentTotalPCScoreList(dto));
    }

    /**
     * 分类成绩查询-老师端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/teacher/type/score")
    public R<CourseContentTotalScorePCResultDTO> teacherTypeScore(CourseTotalScoreStudentQueryDTO dto) {
        return R.data(courseTotalScoreTypeService.pcTeacherTypeScore(dto));
    }

    /**
     * 分类成绩查询-老师端-分页
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/teacher/type/score/page")
    public R<PageInfo<TotalScoreStudentListDTO>> teacherTypeScorePage(@Validated CourseTotalScoreTypeQueryDTO dto) {
        return R.data(courseTotalScoreTypeService.teacherTypeScorePage(dto));
    }

    /**
     * 总成绩查询-学生端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/all/score")
    public R<TotalScoreStudentScoreDTO> allScore(CourseTotalScoreStudentQueryDTO dto) {
        if (dto.getStudentId() == null) {
            dto.setStudentId(LoginHelper.getUserId());
        }
        return R.data(courseTotalScoreTypeService.allStudentScore(dto));
    }

    /**
     * 分类成绩查询-学生端
     * @param dto 初始化参数
     * @return
     */
    @GetMapping("/type/score")
    public R<TotalScoreStudentTypeMsgDTO> typeScore(CourseTotalScoreTypeQueryDTO dto) {
        dto.setStudentId(LoginHelper.getUserId());
        return R.data(courseTotalScoreTypeService.typeScore(dto));
    }




}
